Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
c784058 to
fdc5e96
Compare
bd15b3e to
38470b2
Compare
| $block_type = str_starts_with( $block_type, 'core/' ) | ||
| ? substr( $block_type, /* 'core/' */ 5 ) | ||
| : $block_type; | ||
|
|
||
| $filtered_attributes = filter_block_kses_value( | ||
| $original_attributes, | ||
| $this->allowed_html, | ||
| $this->allowed_protocols, | ||
| array( 'blockName' => $block_type ) | ||
| ); | ||
|
|
||
| if ( $original_attributes !== $filtered_attributes ) { | ||
| $serialized_attributes = serialize_block_attributes( $filtered_attributes ); | ||
| $voider = WP_Block_Processor::VOID === $block_processor->get_delimiter_type() ? '/' : ''; | ||
| $text = " wp:{$block_type} {$serialized_attributes} {$voider}"; |
There was a problem hiding this comment.
The full normalized version of $block_type (including core/ prefix) must happen after filter_block_kses_value because that expects to be passed the complete block type including the core/ prefix. See:
wordpress-develop/src/wp-includes/blocks.php
Lines 2196 to 2198 in 88f2c9e
It's essential to remove the core/ implicit prefix for the serialization, but not before:
| $block_type = str_starts_with( $block_type, 'core/' ) | |
| ? substr( $block_type, /* 'core/' */ 5 ) | |
| : $block_type; | |
| $filtered_attributes = filter_block_kses_value( | |
| $original_attributes, | |
| $this->allowed_html, | |
| $this->allowed_protocols, | |
| array( 'blockName' => $block_type ) | |
| ); | |
| if ( $original_attributes !== $filtered_attributes ) { | |
| $serialized_attributes = serialize_block_attributes( $filtered_attributes ); | |
| $voider = WP_Block_Processor::VOID === $block_processor->get_delimiter_type() ? '/' : ''; | |
| $text = " wp:{$block_type} {$serialized_attributes} {$voider}"; | |
| $filtered_attributes = filter_block_kses_value( | |
| $original_attributes, | |
| $this->allowed_html, | |
| $this->allowed_protocols, | |
| array( 'blockName' => $block_type ) | |
| ); | |
| if ( $original_attributes !== $filtered_attributes ) { | |
| $serialized_attributes = serialize_block_attributes( $filtered_attributes ); | |
| $block_type = str_starts_with( $block_type, 'core/' ) | |
| ? substr( $block_type, /* 'core/' */ 5 ) | |
| : $block_type; | |
| $voider = WP_Block_Processor::VOID === $block_processor->get_delimiter_type() ? '/' : ''; | |
| $text = " wp:{$block_type} {$serialized_attributes} {$voider}"; |
There was a problem hiding this comment.
already saw that but hadn’t pushed it. thank you!
A few elements ignore a first newline: TEXTAREA, PRE, LISTING. TEXTAREA is already covered by wordpress-develop/src/wp-includes/html-api/class-wp-html-tag-processor.php Lines 4191 to 4200 in f27699d It should be covered on wordpress-develop/src/wp-includes/html-api/class-wp-html-tag-processor.php Lines 3867 to 3879 in f27699d I think the best thing to do here for PRE and LISTING is to always inject a leading newline after their open tag, something like this: $output .= $tag_maker->get_updated_html();
if ( 'html' === $namespace && 'PRE' === $tag_name || 'LISTING' === $tag_name ) {
$output .= "\n";
}I shared a potential test for this, it could probably be added to the idempotency test data set: public function test_pre_leading_newline_is_preserved_and_idempotent(): void {
$input = "<pre>\n\ncode</pre>";
$once = wp_kses( $input, 'post' );
$twice = wp_kses( $once, 'post' );
$this->assertSame( $once, $twice, 'wp_kses() must be idempotent for <pre> content.' );
$this->assertSame( $input, $once, 'wp_kses() must not consume newlines inside <pre>.' );
} |
|
There are some behavioral changes around unclosed blocks. Before, KSES would close them (either as void or with a closing delimiter):
|
Co-Authored-By: Jon Surrell <jonsurrel@git.wordpress.org>
…alues." This reverts commit ba325c1.
Co-Authored-By: Jon Surrell <jonsurrell@git.wordpress.org>
Notably, contents of SCRIPT elements _should not_ be extracted and rendered as HTML text nodes. These are SCRIPT contents, and should be hidden from the page.
…ng the original content.
Trac ticket: Core-65984
Description
Rewrites
wp_kses()to rely on the HTML API for structural and reliable application of sanitization rules, normalizing the output for improved downstream parsing.Notables
wp_kses_force_legacy_parserprovides the choice of whether to use this new parser or stick with the legacy code.Todo
Merge after #13273, which accounts for three of the failing tests.wp_kses(), it’s possible to simply wait until an opened element is closed based on depth, and skip that closing element if it exists.wp_kses()with intentionally-incomplete input, for example, a wrapper opening tag with part of the content, separately from the closer. closing open elements does a good job of isolating content, but legacy behaviors depend too much on the more procedural use ofwp_kses()so isolation cannot be reasonably added without mangling websites.pre_ksesfilters but then callpre_ksesNotes